"""
  # File       : checkPoint.py
  # Time       : 2021/12/13
  # Author     : XGT
  # version    : V1.0.0
  # Description: 跟踪并捕捉函数错误
  # Note       : 使用方法，导入文件.与注解使用方式一致
                 @logu.logExceptionHandler(logu.exceptionHandler)
                 logu 是别名

"""

import logging as log
import functools


def logExceptionHandler(log_func):
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kw):
            result = None
            try:
                result = func(*args, **kw)
            except Exception as ex:
                # 处理异常
                log_func("display call function: %s(), args: %s, kw: %s, raise Excepation " % (
                    func.__name__, args, kw), ex)
                raise
            return result
        return wrapper
    return decorator


def exceptionHandler(exText, ex):
    message = exText + str(ex) + "\n"
    log.error(message, exc_info=True)
    print(message)
